jQuery.validator.addMethod("phoneNo", function(phone_number, element) {
    phone_number = phone_number.replace(/\s+/g, "");
    return this.optional(element) || phone_number.length > 9 &&
            phone_number.match(/^[0-9]{7,15}$/);
}, "Please specify a valid phone number");


jQuery.validator.addMethod("NICNo", function(nic_number, element) { 
    nic_number = nic_number.replace(/\s+/g, "");
    return this.optional(element) || nic_number.length > 5 &&
            nic_number.match(/^[0-9]{9}[V|v|x|X]$/);
}, "Please specify a valid NIC number");

jQuery.validator.addMethod("ageValidate", function(dob, element) {
    var birthDate = new Date(dob);
    var today = new Date();

    var years = (today.getFullYear() - birthDate.getFullYear());

    if (today.getMonth() < birthDate.getMonth() ||
            today.getMonth() == birthDate.getMonth() && today.getDate() < birthDate.getDate()) {
        years--;
    }

    return this.optional(element) || years > 18;
}, "Please Enter a valid age");

$.validator.addMethod("selectBox", function(value, element, arg) {
    return  value != 0;
}, "Value must not equal arg.");

$.validator.addMethod("childTable", function(tableID, element) {
    var table = document.getElementById("childrenTable");
    var rowCount = table.rows.length;
    var result = true;
    for (var i = 0; i < rowCount; i = i + 2) {
        var row = table.rows[i];
        var nameText = row.cells[1].childNodes[0];
        if (nameText.value.length == 0) {
            result = false;
        }
    }
    return  result;
}, "Value must not equal arg.");

$.validator.addMethod("nationality", function(value, element, arg) {
    return $('#nationalityIdtrue').attr('checked') || $('#nationalityIdfalse').attr('checked');
}, "Nationality");

/*jQuery.validator.addMethod("math", function(value, element, params) {
 return this.optional(element) || value == params[0] + params[1];
 }, jQuery.format("Please enter the correct value for {0} + {1}"));*/

$.validator.addMethod("positiveNumber", function(value, element, arg) {
    return  value >= 0;
}, "Please Enter a valid Number");

$.validator.addMethod("encroachName", function(value, element, arg) {
    return  (value.length == 0) ? false : true;
}, function() {
    return $('#enterEncroacherName').val();
});

$.validator.addMethod("occupierName", function(value, element, arg) {
    return  (value.length == 0) ? false : true;
}, function() {
    return $('#enterOccupierName').val();
});

$.validator.addMethod("childName", function(value, element, arg) {
    return  (value.length == 0) ? false : true;
}, function() {
    return $('#enterChildName').val();
});


jQuery.validator.addMethod("isFeatureDate", function(dob, element) {
    var birthDate = new Date(dob);
    var today = new Date();

    return this.optional(element) || today >= birthDate;
}, "Future date can't be accepted");

$.validator.addMethod("isValidLotNumber", function(value, element, arg) {
    var res = false;
    var intRegex = /^[\d\,]+$/;

    if (intRegex.test(value)) {
        res = true;
    } else {
        if (value == '') {
            res = true;
        } else {
            res = false;
        }

    }

    return  res;
}, "Please Enter a valid Lot Number");

$.validator.addMethod("isObjection", function(value, element, arg) {

    return  (value.length == 0) ? false : true;
}, "This field is required for add objection");

